/******************************************************************************
*  Filename:       rf_patch_rfe_ghs.h
*  Revised:        $Date: 2019-01-31 15:04:25 +0100 (to, 31 jan 2019) $
*  Revision:       $Revision: 18842 $
*
*  Description: RF core patch for CC13x0 Generic 4FSK up to 1.5Mbps
*
*  Copyright (c) 2015-2019, Texas Instruments Incorporated
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions are met:
*
*  1) Redistributions of source code must retain the above copyright notice,
*     this list of conditions and the following disclaimer.
*
*  2) Redistributions in binary form must reproduce the above copyright notice,
*     this list of conditions and the following disclaimer in the documentation
*     and/or other materials provided with the distribution.
*
*  3) Neither the name of the ORGANIZATION nor the names of its contributors may
*     be used to endorse or promote products derived from this software without
*     specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
*  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
*  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
*  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
*  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
*  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
*  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
*  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
*  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/


#ifndef _RF_PATCH_RFE_GHS_H
#define _RF_PATCH_RFE_GHS_H

#include <stdint.h>
#include "../inc/hw_types.h"

#ifndef RFE_PATCH_TYPE
#define RFE_PATCH_TYPE static const uint32_t
#endif

#ifndef PATCH_FUN_SPEC
#define PATCH_FUN_SPEC static inline
#endif

#ifndef RFC_RFERAM_BASE
#define RFC_RFERAM_BASE 0x2100C000
#endif

#ifndef RFE_PATCH_MODE
#define RFE_PATCH_MODE 0
#endif

RFE_PATCH_TYPE patchGhsRfe[498] = { 
   0x00006256,
   0x1307147f,
   0x24f1004d,
   0x3f131f2e,
   0x0100003f,
   0xff071f00,
   0x4030f00f,
   0x40014000,
   0x40074003,
   0x404f400f,
   0x41cf40cf,
   0x47cf43cf,
   0x3fcf4fcf,
   0x1fcf2fcf,
   0x00000fcf,
   0x00000000,
   0x00000000,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x000000a5,
   0x00000000,
   0x005500a5,
   0x00550055,
   0x00550050,
   0x00550055,
   0x00aa0050,
   0x00aa00aa,
   0x00aa0005,
   0x00aa00aa,
   0x00000005,
   0x00000000,
   0x00000000,
   0x00000000,
   0x000f0000,
   0x00000008,
   0x0000003f,
   0x003f0040,
   0x00040000,
   0x000e0068,
   0x000600dc,
   0x001a0043,
   0x00000005,
   0x00020000,
   0x003f0000,
   0x00000000,
   0x00c00004,
   0x00040000,
   0x000000c0,
   0x00000007,
   0x00000000,
   0x00000000,
   0x00000000,
   0x00000000,
   0xc0500000,
   0x70009100,
   0x9100c070,
   0x31827000,
   0x91310021,
   0x7000b110,
   0xb1018101,
   0x3182a100,
   0xb1109132,
   0x10119101,
   0x22418141,
   0x06f140a0,
   0xc0517000,
   0x18309101,
   0x31833910,
   0x3118d008,
   0x00316f41,
   0xb1109131,
   0x16141483,
   0x700068ac,
   0xc0501025,
   0xc3f49100,
   0x1420c0d0,
   0x10316f03,
   0xc0220441,
   0x00213182,
   0xb1109131,
   0x10313963,
   0xc0820441,
   0x00213182,
   0xb1109131,
   0x10313963,
   0x3182c0a2,
   0x91310021,
   0x1052b110,
   0x31151050,
   0x92051405,
   0x39448244,
   0x31431023,
   0x92431443,
   0x10308243,
   0xc1d13920,
   0x6f151401,
   0x31130633,
   0x40e71e03,
   0x06353835,
   0x1c2440ef,
   0x26f54cee,
   0x60ef90e5,
   0x700090e5,
   0xc0526490,
   0x06311031,
   0x02c13161,
   0xc1126493,
   0x39211031,
   0x31510671,
   0x649302e1,
   0x82207000,
   0x041078a1,
   0x663d4168,
   0xc088664c,
   0x39508220,
   0x1e003980,
   0xc041410e,
   0x14183001,
   0xc0891a18,
   0x39608230,
   0x1e003980,
   0xc0414118,
   0x14193001,
   0x648d1a19,
   0xb1109136,
   0xb1109134,
   0x7100b054,
   0xb064a054,
   0x220080f0,
   0x1240411e,
   0xb03290b0,
   0xc1116490,
   0x6493c122,
   0x692dc170,
   0xc0c2c111,
   0xc1706493,
   0xc0506932,
   0x72279100,
   0x16159298,
   0x10421614,
   0xc1f01053,
   0x31318221,
   0x39813931,
   0xb0513131,
   0x6625b270,
   0x92997227,
   0x1062b270,
   0xc3f01073,
   0x31218231,
   0x39813921,
   0x6625101b,
   0x3182c0e2,
   0x31808260,
   0x00023980,
   0x7100b061,
   0xb1109132,
   0xb061a051,
   0x82537227,
   0x39533953,
   0xc23064f0,
   0x00006962,
   0x90b01280,
   0x7000b032,
   0x9101c051,
   0xc0e2cc01,
   0x64906493,
   0xc0c2c111,
   0xb0546493,
   0xa0547100,
   0x80f0b064,
   0x41712200,
   0x90b01240,
   0xc2f0b032,
   0xc111697c,
   0x6493c122,
   0x6981c0b0,
   0x9101c051,
   0x3182c0e2,
   0x00028260,
   0xb1109132,
   0x39538253,
   0x64f03953,
   0x698fc050,
   0x12800000,
   0xb03290b0,
   0x82537000,
   0x821064f0,
   0x419d22f0,
   0x0000c960,
   0x8220699b,
   0x041078a1,
   0xc05041d0,
   0x72279100,
   0x10629299,
   0xc3f01073,
   0x31218231,
   0x39813921,
   0xb270b051,
   0x72276631,
   0xb2709298,
   0x10531042,
   0x8221c1f0,
   0x39313131,
   0x31313981,
   0x6631101a,
   0xb061a051,
   0xc0b07227,
   0x649069c0,
   0xc122c101,
   0xc1016493,
   0x6493c0c2,
   0x648d1a15,
   0xb1109135,
   0x90b012c0,
   0x7000b032,
   0xc1016490,
   0x6493c122,
   0xc0c2c101,
   0x82536493,
   0x12c064f0,
   0xb03290b0,
   0x64907000,
   0xc081c272,
   0xc1226493,
   0x6493c111,
   0xc111c002,
   0xc0626493,
   0x6493c331,
   0xc111c362,
   0xc3026493,
   0x6493c111,
   0x39538253,
   0xc3e264f0,
   0x22116498,
   0xc24241f3,
   0x6493c881,
   0xc111c252,
   0xc2726493,
   0x6493cee1,
   0xc881c202,
   0xc2026493,
   0x6493c801,
   0x6a07c0b0,
   0x64907000,
   0xc801c242,
   0xc2526493,
   0x6493c011,
   0xc0e1c272,
   0xc0026493,
   0x6493c101,
   0xc301c062,
   0xc1226493,
   0x6493c101,
   0xc101c362,
   0xc3026493,
   0x6493c101,
   0x64f08253,
   0xb0617000,
   0x14127100,
   0x4e2d1c23,
   0xb1109133,
   0x91327000,
   0x6a25b110,
   0xb0617000,
   0x18137100,
   0x4a391c32,
   0xb1109132,
   0x91337000,
   0x6a31b110,
   0xc0c27000,
   0x10156498,
   0x1612c0c2,
   0x31416498,
   0xc0c01415,
   0x14053180,
   0x78b01054,
   0x70000404,
   0x3186c0e6,
   0x1416cc01,
   0x82611067,
   0x0401c3f0,
   0x70001417,
   0x72057306,
   0x720e720b,
   0x7100b050,
   0xb0608081,
   0x8092a050,
   0x46762241,
   0xc1f18080,
   0x16300410,
   0x14011101,
   0x62896c01,
   0x628b628a,
   0x628d628c,
   0x628f628e,
   0x62936291,
   0x62896295,
   0x63db63d8,
   0xc0f28091,
   0x31210421,
   0x2a428082,
   0x16321412,
   0x14211101,
   0x629f6c01,
   0x62a562bb,
   0x629f63db,
   0x62a562bb,
   0x629763db,
   0x62976297,
   0x62976297,
   0x64ff6297,
   0x65956297,
   0x65dd6297,
   0x66096297,
   0x12106297,
   0x720e90b0,
   0x72057306,
   0x90301210,
   0xcff0625a,
   0xc64467de,
   0xc3c0c003,
   0x784064a5,
   0x78509150,
   0x78609210,
   0x78709220,
   0x78809230,
   0x78909260,
   0x78309290,
   0x82109190,
   0x06f03940,
   0x31101001,
   0x92001410,
   0xa0e06297,
   0x80f0a054,
   0x46c42250,
   0x22008040,
   0x62bc47cd,
   0x822da040,
   0x398d318d,
   0xc0f18210,
   0x10090410,
   0x394a821a,
   0x8210041a,
   0x04103980,
   0x10ab100e,
   0x10c010bc,
   0x14c03140,
   0x10c29240,
   0xcfe064b4,
   0xb01367de,
   0x67a3b003,
   0xb050b053,
   0xb064b054,
   0x675bb013,
   0x22e08210,
   0x679446ee,
   0x91c081b0,
   0xb06381d5,
   0x80417100,
   0x47cd2201,
   0x221080f0,
   0xb064472a,
   0x42ee2231,
   0x81b0b063,
   0x81d391c0,
   0x4f0118d3,
   0x67a981d5,
   0x710062ee,
   0x22018041,
   0x80f047cd,
   0x472a2210,
   0x2231b064,
   0xb0634301,
   0x91c081b0,
   0x105081d3,
   0x18301035,
   0x4eee16a0,
   0x4aee18d3,
   0x1cbc6750,
   0x10b242ee,
   0x10bc64b4,
   0xcfd0675b,
   0x637267de,
   0x221080f0,
   0x10a2472a,
   0x675b64b4,
   0x675b675b,
   0x62c4675b,
   0x816fb064,
   0x3d8f318f,
   0x92ffdfc0,
   0x710067de,
   0x22018041,
   0xb06447cd,
   0x225080f0,
   0xb0634345,
   0x22c18211,
   0x67a9473f,
   0x82116331,
   0x473122d1,
   0x221080f0,
   0x8161472a,
   0x31818172,
   0x31823d81,
   0xefb03d82,
   0x930292f1,
   0x62bb67de,
   0x81e391c3,
   0x1cab183b,
   0x10ab4b57,
   0x1c9b7000,
   0x109b4f5a,
   0x82307000,
   0x823106f0,
   0x06f13941,
   0x3012c012,
   0x7100b063,
   0x436d1e01,
   0x81611618,
   0x3d813181,
   0x1c281416,
   0xb0314770,
   0xc006c008,
   0x70006b62,
   0xb0638290,
   0x80417100,
   0x47cd2201,
   0x221180f1,
   0x10074793,
   0x91c081b0,
   0x18d381d3,
   0x4b8e18e3,
   0x675014e3,
   0x438e1cbc,
   0x64b410b2,
   0x820310bc,
   0x92f3dfa0,
   0x675b67de,
   0x107067a9,
   0xcf906b73,
   0x632067de,
   0x91c281b2,
   0x820181d2,
   0x81511812,
   0xc7f11812,
   0x4f9f1421,
   0x9162c812,
   0xb0319172,
   0xc0087000,
   0xc800c006,
   0x91709160,
   0x82017000,
   0x91c081b0,
   0x181081d0,
   0x18108151,
   0x82311406,
   0x06f13941,
   0x43be1e01,
   0xc0101618,
   0x1c083010,
   0x106047cc,
   0x10063c10,
   0x1461c7f1,
   0xc8164fc2,
   0x81719166,
   0x3d813181,
   0x4bc91c16,
   0xb0319176,
   0xc008c006,
   0x82017000,
   0x31828162,
   0xef803d82,
   0x930292f1,
   0xa00367de,
   0x62976609,
   0x64b480a2,
   0xb0506297,
   0x62977100,
   0x82d092e0,
   0x47df2200,
   0x7000b2c0
};

PATCH_FUN_SPEC void rf_patch_rfe_ghs(void)
{
#ifdef __PATCH_NO_UNROLLING
   uint32_t i;
   for (i = 0; i < 498; i++) {
      HWREG(RFC_RFERAM_BASE + 4 * i) = patchGhsRfe[i];
   }
#else
   const uint32_t *pS = patchGhsRfe;
   volatile unsigned long *pD = &HWREG(RFC_RFERAM_BASE);
   uint32_t t1, t2, t3, t4, t5, t6, t7, t8;
   uint32_t nIterations = 62;

   do {
      t1 = *pS++;
      t2 = *pS++;
      t3 = *pS++;
      t4 = *pS++;
      t5 = *pS++;
      t6 = *pS++;
      t7 = *pS++;
      t8 = *pS++;
      *pD++ = t1;
      *pD++ = t2;
      *pD++ = t3;
      *pD++ = t4;
      *pD++ = t5;
      *pD++ = t6;
      *pD++ = t7;
      *pD++ = t8;
   } while (--nIterations);

   t1 = *pS++;
   t2 = *pS++;
   *pD++ = t1;
   *pD++ = t2;
#endif
}

#endif
